package com.yf.dmp.service;

import com.alibaba.fastjson.JSON;
import com.yf.dmp.bean.QueryInfo;
import com.yf.dmp.bean.SystemInfo;
import com.yf.dmp.dao.SystemInfoDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;

@Service
@Transactional
public class SystemInfoService {
    @Autowired
    private SystemInfoDao systemDao;

    public String getSystemInfo(QueryInfo queryInfo){
        int num = systemDao.getSystemInfoCount("%" + queryInfo.getQuery() + "%");
        int pageStart = (queryInfo.getPageNum() - 1) * queryInfo.getPageSize();
        List<SystemInfo> si = systemDao.getSystemInfo("%" + queryInfo.getQuery() + "%", pageStart, queryInfo.getPageSize());
        HashMap<String, Object> res = new HashMap<>();
        res.put("num", num);
        res.put("data", si);
        String jsonstr = JSON.toJSONString(res);
        return jsonstr;
    };

    public int addSystemInfo(SystemInfo sl){
        return systemDao.addSystemInfo(sl);
    };
    public int getSystemInfoCount(String code){
        return systemDao.getSystemInfoCount(code);
    };
    public int deleteSystemInfoById(int id){
        return systemDao.deleteSystemInfoById(id);
    };
    public SystemInfo getUpdateSystemInfo(int id){
        return systemDao.getUpdateSystemInfo(id);
    };
    public int updateSystemInfo(SystemInfo sl){
        return systemDao.updateSystemInfo(sl);
    };


}
